package com.pronhub.luowowo.website.web.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.pronhub.luowowo.member.domain.UserInfo;
import com.pronhub.luowowo.member.service.IUserInfoService;
import com.pronhub.luowowo.util.AjaxResult;
import com.pronhub.luowowo.website.web.annotation.RequireLogin;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class LoginController {
    @Reference
    private IUserInfoService userInfoService;
    @RequireLogin
    @RequestMapping("/hello")
    @ResponseBody
    public Object get(Long id){
        System.err.println(id);
        UserInfo userInfo = userInfoService.selectByID(id);
        return userInfo;
    }

    /**
     * 检查用户是否存在
     * @param phone 手机号码
     * @return
     */

    @RequestMapping("/checkPhone")
    @ResponseBody
    public Object checkPhone(String phone){
        boolean b = userInfoService.checkPhone(phone);
        return !b;
    }

    /**
     * 发哦是哪个验证码 根据手机号码来发送验证码 注册所需要的验证码
     * @param phone 验证码
     * @return Json数据
     */
    @RequestMapping("/sendVerifyCode")
    @ResponseBody
    public Object sendVerifyCode(String phone){
        try {
            userInfoService.sendVerifyCode(phone);
        }catch (Exception e){
            e.printStackTrace();
        }
        return AjaxResult.SUCCESS;
    }
    @RequestMapping("/userRegist")
    @ResponseBody
    public Object userRegist(String phone,String nickname,String password,String rpassword,String verifyCode){
            userInfoService.userRegist(phone,nickname,password,rpassword,verifyCode);
        return AjaxResult.SUCCESS;
    }

}
